package com.ruoyi.web.controller.laiqianba.sms;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.db.model.SmsRecordVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SmsRecordInfo;
import com.ruoyi.laiqianba.service.ISmsRecordInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信发送记录Controller
 * 
 * @author ruoyi
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/sms/recordInfo")
public class SmsRecordInfoController extends BaseController
{
    @Autowired
    private ISmsRecordInfoService smsRecordInfoService;

    /**
     * 查询短信发送记录列表
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsRecordInfo smsRecordInfo)
    {
        startPage();
        List<SmsRecordInfo> list = smsRecordInfoService.selectSmsRecordInfoList(smsRecordInfo);
        return getDataTable(list);
    }

    /**
     * 导出短信发送记录列表
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:export')")
    @Log(title = "短信发送记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsRecordInfo smsRecordInfo)
    {
        List<SmsRecordInfo> list = smsRecordInfoService.selectSmsRecordInfoList(smsRecordInfo);
        ExcelUtil<SmsRecordInfo> util = new ExcelUtil<SmsRecordInfo>(SmsRecordInfo.class);
        util.exportExcel(response, list, "短信发送记录数据");
    }

    /**
     * 获取短信发送记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smsRecordInfoService.selectSmsRecordInfoById(id));
    }

    /**
     * 新增短信发送记录
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:add')")
    @Log(title = "短信发送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsRecordInfo smsRecordInfo)
    {
        return toAjax(smsRecordInfoService.insertSmsRecordInfo(smsRecordInfo));
    }

    /**
     * 修改短信发送记录
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:edit')")
    @Log(title = "短信发送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsRecordInfo smsRecordInfo)
    {
        return toAjax(smsRecordInfoService.updateSmsRecordInfo(smsRecordInfo));
    }

    /**
     * 删除短信发送记录
     */
    @PreAuthorize("@ss.hasPermi('sms:recordInfo:remove')")
    @Log(title = "短信发送记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsRecordInfoService.deleteSmsRecordInfoByIds(ids));
    }

    /**
     * 短信营销结果查询
     */
    @PostMapping("list/result")
    public TableDataInfo listResult(@RequestBody SmsRecordInfo smsRecordInfo){
        startPage();
        List<SmsRecordVo> list = smsRecordInfoService.getListResult(smsRecordInfo);
        return getDataTable(list);
    }

}
